package sortedAlgorithmCollections;

/**
 * 希尔排序
 * @author le
 */
public class ShellSort {

    public static void main(String[] args) {

        // 待排序的数组
        int[] nums = {1, 56, 8, 9, 65, 88,10};

        int len = nums.length;
        int temp;

        // 设置排序的增量
        for (int step = len/2; step >= 1; step /= 2){
            // 每执行一次循环 增量减少一半
            for (int i = step;i < len;i++){
                temp = nums[i];
                int j = i - step;
                while (j >= 0 && nums[j] > temp) {
                    nums[j + step] = nums[j];
                    j -= step;
                }
                nums[j + step] = temp;
            }
        }

        for (int num : nums) {
            System.out.println(num);
        }


    }
}
